草庐IT

javascript - 通过脚本弹出widget

全部标签

ruby-on-rails - 通过生成器添加从 Rails 引擎 gem 到应用程序的新迁移

我正在用ruby​​gem构建Rails引擎。它现在包括一些在您运行时调用的迁移:railsgmyengine:install生成器中的代码如下:moduleMyEnginemoduleGeneratorsclassInstallGenerator但是,如果我再次运行railsgmyengine:install,它会失败并出现以下错误:Anothermigrationisalreadynamedmigration1:/Users/jh/Code/Web/demoapp/db/migrate/20130327222221_migration1.rb我希望它只是默默地忽略已经存在迁移的事实

ruby - 如何从 ruby​​ 脚本中引用本地 gem?

我需要从一个普通的ruby​​脚本中引用一个本地gem,而不需要安装gem。追踪Howtoreferalocalgeminruby?,我尝试使用以下设置创建一个Gemfile:%w(custom_gemanother_custom_gem).eachdo|dependency|gemdependency,:path=>File.expand_path("../../#{dependency}",__FILE__)end脚本如下所示:require'custom_gem'CustomGem::Do.something当我执行此操作时:bundleexecrubyscript.rb我得到:

ruby-on-rails - 无法通过 Homebrew 启动 elasticsearch 服务器

所以我通过brew安装了elasticsearch:$brewinstallelasticsearch然后当我运行elasticsearch服务器时:elasticsearch-f-Des.config=/usr/local/Cellar/elasticsearch/0.19.3/config/elasticsearch.yml我收到这个错误:{0.20.4}:SetupFailed...-FailedToResolveConfigException[Failedtoresolveconfigpath[/usr/local/Cellar/elasticsearch/0.19.3/con

ruby - 如何获得 JavaScript 样式的哈希访问?

我知道ActiveSupport提供了此功能。h=ActiveSupport::OrderedOptions.newh.boy='John'h.girl='Mary'h.boy#=>'John'h.girl#=>'Mary'但是我已经有一个很大的散列,我想使用点表示法访问该散列。这是我尝试过的:large_hash={boy:'John',girl:'Mary'}h=ActiveSupport::OrderedOptions.new(large_hash)h.boy#=>nil那没有用。我怎样才能使这项工作。我正在使用ruby1.9.2更新:抱歉,我应该提到我不能使用openstruc

ruby - 通过 RVM 在 Ubuntu、Ruby 1.9.2 上安装使用 native 扩展的 gem 时出错

我在尝试安装ffigem时遇到错误:~-16:54>gemiffiBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingffi:ERROR:Failedtobuildgemnativeextension.rakeRUBYARCHDIR=/home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/libRUBYLIBDIR=/home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/lib/home/mdem

ruby 通过重复字符或空格拆分字符串

我如何分割这个字符串。"68855588866887777"=>["6","88","555","8","88","66","88","7777"]我试过了,但是没用。ruby-1.8.7-p334:020>"111133".split(/(\d)\1+/)=>["","1","","3"] 最佳答案 split将只使用它匹配的任何内容作为分隔符,并将其从相关字符串中删除。您要找的是scan:str="68855588866887777"str.scan(/((\d)\2*)/).map(&:first)#=>["6","88","

ruby-on-rails - RSpec:通过正则表达式匹配字符串数组

我正在使用rspec测试我的模型的验证,并期待一条错误消息。但是,消息的确切文本可能会发生变化,所以我想更宽容一点,只检查部分消息。由于Spec::Matchers::include方法只适用于字符串和集合,我目前正在使用这个结构:@user.errors[:password].any?{|m|m.match(/istooshort/)}.shouldbe_true这可行,但对我来说似乎有点麻烦。是否有更好(即更快或更像ruby​​)的方法来检查数组是否包含正则表达式的字符串,或者是否有一个rspec匹配器可以做到这一点? 最佳答案

ruby - CSV 到 JSON Ruby 脚本?

有谁知道如何编写将csv文件转换为json文件的Ruby脚本?CSV格式如下:Canon,DigitalIXUS70,"Epic,Epic100",3x,Yes(lockable),Yes(lockable),YesCanon,DigitalIXUS75,"Epic,Epic100",3x,Yes(lockable),Yes(lockable),YesCanon,DigitalIXUS80,"Epic,Epic100",3x,Yes(lockable),Yes(lockable),YesJSON需要产生这样的结果:{"aaData":[["Canon","DigitalIXUS70",

ruby - 尝试通过 SSL 创建一个简单的 Ruby 服务器

我正在尝试用Ruby创建一个简单的SSL客户端和服务器。但是我收到了一条神秘的错误消息,文档也没有帮助。这是我的服务器代码:#!/usr/bin/rubyrequire"gserver"require"openssl"listeningPort=Integer(ARGV[0])classServer"+lineInlineOut="Yousaid:"+lineIn$stdout.puts"客户端代码类似:#!/usr/bin/rubyrequire"socket"require"thread"require"openssl"host=ARGV[0]port=Integer(ARGV[1

ruby - 将ruby脚本编译成exe?

是否可以在Windows上将ruby​​脚本编译成.exe文件?我到处搜索并尝试了以下方法(看起来RubyScript2EXE、Shoes和Crate似乎都死了或被遗弃了。):http://ocra.rubyforge.org/http://exerb.sourceforge.jp/index.en.html我在Windows7Ultimate(64位)上使用Ruby1.8.7从一个干净的系统我这样做:从ruby​​installer.org安装RubyInstaller1.8.7-p358gem安装watirgem安装ocragitclonegit://github.com/snau